<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>chnmix</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="chnget.html" title="chnget" />
    <link rel="next" href="chnparams.html" title="chnparams" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">chnmix</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="chnget.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="chnparams.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="chnmix"></a>
      <div class="titlepage"></div>
      <a id="Indexchnmix" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">chnmix</span>
        </h2>
        <p>chnmix — 
      Writes audio data to the named software bus, mixing to the previous
      output.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp94009136"></a>
        <h2>Description</h2>
        <p>
      Adds an audio signal to a channel of the named software bus.
      Implies declaring the channel with <span class="emphasis"><em>imode</em></span>=2 (see also
      <a class="link" href="chn.html" title="chn"><em class="citetitle">chn_a</em></a>).
    </p>
      </div>
      <div class="refsect1">
        <a id="idp94051728"></a>
        <h2>Syntax</h2>
        <pre class="synopsis"><span class="command"><strong>chnmix</strong></span> aval, Sname</pre>
      </div>
      <div class="refsect1">
        <a id="idp94053776"></a>
        <h2>Initialization</h2>
        <p>
      <span class="emphasis"><em>Sname</em></span> -- a string that indicates which
      named channel of the software bus to write.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp94055488"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>aval</em></span> -- the audio signal to write at performance
      time.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp94057120"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the chnmix opcode. It uses the file <a class="ulink" href="examples/chnmix.csd" target="_top"><em class="citetitle">chnmix.csd</em></a>.
      </p>
        <div class="example">
          <a id="idp94058976"></a>
          <p class="title">
            <strong>Example 114. Example of the chnmix opcode.</strong>
          </p>
          <div class="example-contents">
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
-odac     <span class="comment">;;;realtime audio out</span>
<span class="comment">;-iadc    ;;;uncomment -iadc if realtime audio input is needed too</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o chnmix.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>
<span class="comment">;Example by Joachim Heintz</span>
<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">ksmps</span> <span class="op">=</span> 32
<span class="ohdr">nchnls</span> <span class="op">=</span> 2
<span class="ohdr">0dbfs</span> <span class="op">=</span> 1

  <span class="oblock">instr</span> 1<span class="comment">; send i-values</span>
          <span class="opc">chnset</span>    1, "sio"
          <span class="opc">chnset</span>    <span class="op">-</span>1, "non"
  <span class="oblock">endin</span>

  <span class="oblock">instr</span> 2<span class="comment">; send k-values</span>
kfreq     <span class="opc">randomi</span>   100, 300, 1
          <span class="opc">chnset</span>    kfreq, "cntrfreq"
kbw       <span class="op">=</span>         kfreq<span class="op">/</span>10
          <span class="opc">chnset</span>    kbw, "bandw"
  <span class="oblock">endin</span>

  <span class="oblock">instr</span> 3<span class="comment">; send a-values</span>
anois     <span class="opc">rand</span>      .1
          <span class="opc">chnset</span>    anois, "noise"
 loop<span class="op">:</span>
idur      <span class="opc">random</span>    .3, 1.5
          <span class="octrl">timout</span>    0, idur, do
          <span class="opc">reinit</span>    loop
 do<span class="op">:</span>
ifreq     <span class="opc">random</span>    400, 1200
iamp      <span class="opc">random</span>    .1, .3
asig      <span class="opc">oscils</span>    iamp, ifreq, 0
aenv      <span class="opc">transeg</span>   1, idur, <span class="op">-</span>10, 0
asine     <span class="op">=</span>         asig <span class="op">*</span> aenv
          <span class="opc">chnset</span>    asine, "sine"
  <span class="oblock">endin</span>

  <span class="oblock">instr</span> 11<span class="comment">; receive some chn values and send again</span>
ival1     <span class="opc">chnget</span>    "sio"
ival2     <span class="opc">chnget</span>    "non"
          <span class="opc">print</span>     ival1, ival2
kcntfreq  <span class="opc">chnget</span>    "cntrfreq"
kbandw    <span class="opc">chnget</span>    "bandw"
anoise    <span class="opc">chnget</span>    "noise"
afilt     <span class="opc">reson</span>     anoise, kcntfreq, kbandw
afilt     <span class="opc">balance</span>   afilt, anoise
          <span class="opc">chnset</span>    afilt, "filtered"
  <span class="oblock">endin</span>

  <span class="oblock">instr</span> 12<span class="comment">; mix the two audio signals</span>
amix1     <span class="opc">chnget</span>     "sine"
amix2     <span class="opc">chnget</span>     "filtered"
          <span class="opc">chnmix</span>     amix1, "mix"
          <span class="opc">chnmix</span>     amix2, "mix"
  <span class="oblock">endin</span>

  <span class="oblock">instr</span> 20<span class="comment">; receive and reverb</span>
amix      <span class="opc">chnget</span>     "mix"
aL, aR    <span class="opc">freeverb</span>   amix, amix, .8, .5
          <span class="opc">outs</span>       aL, aR
  <span class="oblock">endin</span>

  <span class="oblock">instr</span> 100<span class="comment">; clear</span>
          <span class="opc">chnclear</span>   "mix"
  <span class="oblock">endin</span>

<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="stamnt">i</span> 1 0 20
<span class="stamnt">i</span> 2 0 20
<span class="stamnt">i</span> 3 0 20
<span class="stamnt">i</span> 11 0 20
<span class="stamnt">i</span> 12 0 20
<span class="stamnt">i</span> 20 0 20
<span class="stamnt">i</span> 100 0 20
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp94060896"></a>
        <h2>Credits</h2>
        <p>
      </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Author: Istvan Varga</td>
          </tr>
          <tr>
            <td>2006</td>
          </tr>
        </table>
        <p>
    </p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="chnget.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="chnparams.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">chnget </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> chnparams</td>
        </tr>
      </table>
    </div>
  </body>
</html>
